﻿using NFine.Application.Biz;
using NFine.Application.SystemManage;
using NFine.Code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NFine.Web.Areas.BizManage.Controllers
{
    public class ZhongZhuanPinJianController : ControllerBase
    {
        //
        // GET: /BizManage/ZhongZhuanPinJian/

        private ZhongZhuanPinJianApp zhzhapp = new ZhongZhuanPinJianApp();
        private HuangouIntegralApp huangouIntegralApp = new HuangouIntegralApp();
        private UserApp userApp = new UserApp();

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult MemberIndex()
        {
            return View();
        }


        //[HttpPost]
        //[HandlerAjaxOnly]
        //[HandlerLogin]
        public ActionResult GetGridJson(Pagination pagination,string OrderTimeStart, string OrderTimeEnd,string type="-1")
        {
            DateTime dtstart = new DateTime(2000, 1, 1);
            if (!DateTime.TryParse(OrderTimeStart, out dtstart))
            {
                dtstart = new DateTime(2000, 1, 1);
            }
            DateTime dtend = DateTime.Now;
            if (!DateTime.TryParse(OrderTimeEnd, out dtend))
            {
                dtend = DateTime.Now;
            }
            dtend= dtend.AddDays(1);

            var list = zhzhapp.GetList(pagination, dtstart, dtend,int.Parse(type));
            var data = new
            {
                rows = list,
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            //ViewData["curr"] = list.Count > 0 ? list[0].F_Integral : 0;
            //ViewData["dd"] = list.Where(t => t.F_JLIntegral > 0).Sum(t => t.F_JLIntegral);
            //ViewData["shy"] = list.Where(t => t.F_JLIntegral < 0).Sum(t => t.F_JLIntegral);

            return Content(data.ToJson());
        }

        public override ActionResult Form()
        {
            ViewData["TransferCenterList"] = userApp.GetZhzhUser();

            return View();
        }
        [HttpPost]
        [HandlerLogin]
        public ActionResult SubmitForm(string uid, decimal pjint, decimal jlint)
        {
            if (zhzhapp.SubmitForm(uid, pjint, jlint))
            {
                return Success("积分消耗添加完成！");
            }
            else
            {
                return Error("积分消耗添加失败！");
            }
        }

        [HttpPost]
        [HandlerLogin]
        public ActionResult SendJF(DateTime date)
        {
            if (huangouIntegralApp.SendHuangouIntegral(date))
            {
                return Success("日期["+date.ToLongDateString()+"]积分发放添加完成！");
            }
            else
            {
                return Error("积分发放添加失败！");
            }
        }
    }
}
